home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / UTIL / PROCESS.CPP < prev    next >
C/C++ Source or Header  |  1994-12-13  |  5KB  |  196 lines

  1. #include "..\au.hpp"
  2.  
  3. /*************************************************************************/
  4. static void printf_bar(AU *au, int n)
  5. {
  6.     int i;
  7.  
  8.     for (i=0; i < n; i++)
  9.     {
  10.         au_printf_c(au, i % 6 + 9, "-");
  11.     }
  12. }
  13. /*************************************************************************/
  14. static int process_dir(AU *au, int (*func)(AU *, char *), char *file_spec,
  15.                        char sub_dirs)
  16. {
  17.     struct ffblk ffblk;           // directory entry structure
  18.     int count=0;
  19.     int len;
  20.     char hold_dir[FLENGTH];
  21.     LISTPTR file_list;
  22.     LIST *el;
  23.  
  24.     if (!au->no_extra && !au->no_disp_dirs)
  25.     {
  26.         if (strcmp(au->last_dir, au->source_directory) != 0)
  27.         {
  28.             len = (72 - strlen(au->source_directory)) / 2;
  29.             printf_bar(au, len);
  30.             au_printf_c(au, 15, " Dir: %s ", au->source_directory);
  31.             printf_bar(au, len);
  32.             au_printf(au, "\n");
  33.             strcpy(au->last_dir, au->source_directory);
  34.         }
  35.     }
  36.  
  37.     /* gather the file names first */
  38.  
  39.     if (!findfirst("*.*", &ffblk, 0))
  40.     {
  41.         do
  42.         {
  43.             if (strstr(ffblk.ff_name, ".")==NULL)
  44.                 strcat(ffblk.ff_name, ".");
  45.             if (wildcard_compare(au, ffblk.ff_name, file_spec))
  46.             {
  47.                 len = strlen(ffblk.ff_name);
  48.                 if (ffblk.ff_name[len-1] == '.')
  49.                     ffblk.ff_name[len-1] = '\0';
  50.                 if (au->dirs_only)
  51.                 {
  52.                     func(au, ffblk.ff_name);
  53.                     count++;
  54.                     break;
  55.                 }
  56.                 file_list.add(ffblk.ff_name);
  57.             }
  58.         }  while (!findnext(&ffblk));
  59.     }
  60.  
  61.     /* process */
  62.  
  63.     for (el = file_list.head; el != NULL; el = el->next)
  64.     {
  65.         func(au, el->data);
  66.         count++;
  67.     }
  68.     file_list.destroy();
  69.  
  70.     if (sub_dirs)
  71.     {
  72.         if (!findfirst("*.*", &ffblk, FA_DIREC))
  73.         {
  74.             do
  75.             {
  76.                 if (ffblk.ff_attrib & FA_DIREC)
  77.                 {
  78.                     if (ffblk.ff_name[0] != '.')
  79.                     {
  80.                         fix_flist(au, NULL, NULL);
  81.                         cd(au, ffblk.ff_name, hold_dir);
  82.                         getcwd(au->source_directory, FLENGTH);
  83.                         count += process_dir(au, func, file_spec, sub_dirs-1);
  84.                         cd(au, hold_dir);
  85.                     }
  86.                 }
  87.             }  while (!findnext(&ffblk));
  88.         }
  89.     }
  90.     fix_flist(au, NULL, NULL);
  91.     return count;
  92. }
  93. /*************************************************************************/
  94. static int add_def_file_spec_to_list(AU *au, char *string)
  95. {
  96.     char string2[200], string3[200];
  97.  
  98.     strcpy(string2, string);
  99.     for (;;)
  100.     {
  101.         split_string(string2, string3);
  102.         ltrim(string2);
  103.         rtrim(string2);
  104.  
  105.         if (string3[0] == '\0')
  106.             break;
  107.  
  108.         if (string3[0] == '-' && string3[1] == '#')
  109.         {
  110.             fill_list_from_BBS(au, string3+2);
  111.         }
  112.         else if (string3[0] == '@' && access(string3, 0x00) != 0)
  113.         {
  114.             process_at_file(au, &au->process_list, string3+1);
  115.         }
  116.         else
  117.             au->process_list.add(string3);
  118.     }
  119.     return 0;
  120. }
  121. /*************************************************************************/
  122. int process_files(AU *au, int (*func)(AU *, char *))
  123. {
  124.     LIST *el;
  125.     char file_spec[FLENGTH];
  126.     char hold_dir[FLENGTH];
  127.     int count=0;
  128.     int inside_count=0;
  129.  
  130.     if (au->process_list.head == NULL)
  131.     {
  132.         if (au->def_file_spec == NULL || au->def_file_spec[0] == '\0')
  133.             goto Nothing;
  134.         add_def_file_spec_to_list(au, au->def_file_spec);
  135. //          add_to_list(au, &au->process_list, "*.*");
  136.     }
  137.  
  138.     for (el = au->process_list.head; el != NULL; el = el->next)
  139.     {
  140.         split_file(el->data, au->source_directory, file_spec);
  141.         /* Change to cur_directory first in case source_directory is relative
  142.            to it */
  143.         cd(au, au->cur_directory);
  144.         cd(au, au->source_directory, hold_dir);
  145.  
  146.         if (chdir(file_spec) == 0)
  147.             strcpy(file_spec, "*.*");
  148.  
  149.         if (file_spec[0]=='\0')
  150.             strcpy(file_spec, "*.*");
  151.  
  152.         if (!strstr(file_spec, "."))
  153.             strcat(file_spec, ".*");
  154.  
  155.         getcwd(au->source_directory, FLENGTH);
  156.         inside_count += process_dir(au, func, file_spec, au->sub_dirs);
  157.         if (inside_count == 0 && !au->no_extra && !au->dirs_only)
  158.             au_printf_error(au, "No files matching %s", el->data);
  159.  
  160.         count += inside_count;
  161.         cd(au, hold_dir);
  162.     }
  163. Nothing:
  164.     if (count == 0 && !au->no_extra && !au->dirs_only)
  165.         au_printf_c(au, 4, NOTHING);
  166.     return count;
  167. }
  168.  
  169. static int _count;
  170.  
  171. /**************************************************************************/
  172. static int count_file(AU *, char *)
  173. {
  174.     _count++;
  175.     return 0;
  176. }
  177. /**************************************************************************/
  178. int count_process_files(AU *au)
  179. {
  180.     int     old_sub_dirs = au->sub_dirs;
  181.     BOOLEAN old_no_extra = au->no_extra;
  182.     BOOLEAN old_no_disp_dirs = au->no_disp_dirs;
  183.  
  184.  
  185.     _count = 0;
  186.     au->sub_dirs = FALSE;
  187.     au->no_extra = TRUE;
  188.     au->no_disp_dirs = TRUE;
  189.     process_files(au, count_file);
  190.     au->sub_dirs = old_sub_dirs;
  191.     au->no_extra = old_no_extra;
  192.     au->no_disp_dirs = old_no_disp_dirs;
  193.  
  194.     return _count;
  195. }
  196.